/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.A000;
import queenb.net.entitybean.M000;
import queenb.web.store.A000Store;
import queenb.web.store.M000Store;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class M000Controller extends QueenbController {

  
    private int pm000;
    private String mv001;// City Name
    private String mv002;// abbreviation
    private M000Store m000Store;
    private List<SelectItem> combolistM000= new ArrayList<SelectItem>();
    private ComboboxUtil comboboxUtil;

    public M000Controller() throws SQLException, InstantiationException, IllegalAccessException {
        m000Store = new M000Store();
       Object action = getRequest().getParameter("action");
        if (action != null) {
            if (action.equals("editM000")) {
                Object objPM000 = getRequest().getParameter("pm000");
                if (objPM000 != null) {
                    pm000 = Util.parseInt(objPM000);

                    List<M000> list = m000Store.mcurpks_listoftabm000(getLogin().getModule(), getLogin().getCompanyNo(), 0, getLogin().getUserName());
                    if (list != null) {
                        for (int i = 0; i < list.size(); i++) {
                            if (list.get(i).getPm000() == pm000) {
                                mv001 = list.get(i).getMv001();
                                mv002 = list.get(i).getMv002();                            
                            }
                        }
                    }
                }
            } else if (action.equals("deleteM000")) {
                Object objPM000 = getRequest().getParameter("pm000");
                if (objPM000 != null) {
                    pm000 = Util.parseInt(objPM000);
                    SessionProvider.setSessionMapValue("IDM000DELETE", pm000);
                }
            }
        }
    }

    
//     public void stdc_tools_stornotabc350() {
//        try {
//            int count = m000Store.(Util.parseInt(SessionProvider.getSessionMapValue("IDM000DELETE")), getLogin().getUserName());
//            if (count != 0) {
//               
//                System.out.println("-----THAM SO----");
//            } else {
//              
//            }
//        } catch (Exception e) {
//        }
//    }
    public void stdm_tools_inserttabm000() {
        System.out.println("--------------" + mv001+mv002);
            int count = m000Store.stdm_tools_inserttabm000( pm000,getLogin().getModule(),getLogin().getCompanyNo(),mv001,mv002,getLogin().getUserName());
            if (count > 0) {
                showGlobalReport(true, getResourceString("success"));
            } else {
                showGlobalReport(true, getResourceString("error"));
            }          
        sendRedirectUrlTab("setting.jsp?tab=header36&linkM000="+Util.convertMD5(getRequest().getRequestURI()));

    }
    public List<M000> getListAllCity(){
        try {
            List<M000> listM000 = m000Store.mcurpks_listoftabm000(getLogin().getModule(),getLogin().getCompanyNo(),pm000,getLogin().getUserName());
            return listM000;
        } catch (Exception e) {
            return null;
        }
    }
//    
//    public void getListDetalCity(int id){
//        try {
//            List<A000> listByID = getListAllCity();
//            if(listByID != null && listByID.size() > 0){
//                for(int i=0; i < listByID.size();i++){
//                    if(listByID.get(i).getPa000() == id){
//                        this.av001 = listByID.get(i).getAv001();
//                        this.av002 = listByID.get(i).getAv002();
//                        this.fn750 = listByID.get(i).getFn750();
//                        break;
//                    }
//                }
//            }
//        } catch (Exception e) {
//        }
//    }

    /**
     * @return the pm000
     */
    public int getPm000() {
        return pm000;
    }

    /**
     * @param pm000 the pm000 to set
     */
    public void setPm000(int pm000) {
        this.pm000 = pm000;
    }

    /**
     * @return the mv001
     */
    public String getMv001() {
        return mv001;
    }

    /**
     * @param mv001 the mv001 to set
     */
    public void setMv001(String mv001) {
        this.mv001 = mv001;
    }

    /**
     * @return the mv002
     */
    public String getMv002() {
        return mv002;
    }

    /**
     * @param mv002 the mv002 to set
     */
    public void setMv002(String mv002) {
        this.mv002 = mv002;
    }

    /**
     * @return the combolistM000
     */
    public List<SelectItem> getCombolistM000() {
        return combolistM000;
    }

    /**
     * @param combolistM000 the combolistM000 to set
     */
    public void setCombolistM000(List<SelectItem> combolistM000) {
        this.combolistM000 = combolistM000;
    }
   
}
